<?php
class LogAction extends BaseAction {
	function index(){
		$idx = isset($_GET['idx'])?$_GET['idx']:0;
		$sdate = isset($_GET['sdate'])?strtotime($_GET['sdate']):0;
		$edate = isset($_GET['edate'])?strtotime($_GET['edate']):0;
		if($sdate == $edate && $edate == 0){
			$Y = date("Y");
			$m = date("m");
			$d = date("d");
			$sdate = mktime(0,0,0,$m,$d,$Y);
			$edate = mktime(23,59,59,$m,$d,$Y);
		}
		$log=M('Log');
		$where = "row_date>=$sdate AND row_date<=$edate";
		import('ORG.Util.Page');
		$count=$log->where($where)->count();
		$page=new Page($count,C('PAGESIZE'));
		$show=$page->show();
		$this->assign("page",$show);
		//需要查询哪些字段
        $fields = 'id,user,code,ip,row_date';
		$list=$log->order('id desc')->field($fields)->where($where)->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('list',$list);
		//功能模块按钮
		$option = get_option($idx);
		$this->assign('coption',$option);
		$this->display();
	}

	function show(){
		$id=$_GET['id'];
		if(!empty($id)){
			$log=M('Log');
			$date=$log->field('user,code,ip,row_date,msg')->getById($id);
			$this->assign('obj',$date);
		}
		$this->display();
	}

	function delete(){
		$did=$_POST['did'];
		if(!empty($did) && is_array($did)){
			$log=M('Log');
			$id=implode(',',$did);
			if(false!==$log->delete($id)){
				$this->assign('jumpUrl',__URL__.'/index');
				$this->success('操作成功');
			}else{
				$this->error('操作失败：'.$user->getDbError());
			}
		}else{
			$this->error('请选择删除用户');
		}
	}

}
?>